package com.gs.synedocket.model;

import com.gs.synedocket.callback.Callback;
import com.gs.synedocket.model.listener.OnResultListener;
import com.gs.synedocket.util.OKHttpUtil;

import java.lang.reflect.Type;

public class SyncModel {
    public void sync(String table, final OnResultListener onResultListener, Class typeofT) {
        OKHttpUtil.getInstance().getSyncThread(OKHttpUtil.NET_URL + "/api/syns?synObj=" + table,
                new Callback() {
                    @Override
                    public void onSuccess(Object obj) {
                        onResultListener.onSuccess(obj);
                    }

                    @Override
                    public void onFailed(Exception e) {
                        onResultListener.onFails(e);
                    }
                }, typeofT);
    }

    public void syncDocket(String json, final OnResultListener onResultListener, Type typeofT) {
        OKHttpUtil.getInstance().postSyncThread(OKHttpUtil.NET_URL + "/api/syns" ,json,
                new Callback() {
                    @Override
                    public void onSuccess(Object obj) {
                        onResultListener.onSuccess(obj);
                    }

                    @Override
                    public void onFailed(Exception e) {
                        onResultListener.onFails(e);
                    }
                }, typeofT);
    }
}
